package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.mapper.OrdersMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理端-用户下单相关接口")
@RestController("adminOrdersController")
@Slf4j
@RequestMapping("/admin/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 管理端-订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("管理端-订单搜索")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("管理端-订单搜索：{}", ordersPageQueryDTO);
        PageResult pageResult =  ordersService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 管理端-各个状态的订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("管理端-各个状态的订单数量统计")
    public Result<OrderStatisticsVO> statistics(){
        log.info("管理端-各个状态的订单数量统计");
         OrderStatisticsVO orderStatisticsVO  = ordersService.selectOrders();

        return Result.success(orderStatisticsVO);
    }

    /**
     * 管理端-根据订单id查询订单详情
     * @param id
     * @return
     */
    @ApiOperation("管理端-根据订单id查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getDetailsByOrderId(@PathVariable Long id){
        log.info("管理端-根据订单id查询订单详情:{}", id);
        OrderVO orderVO = ordersService.selectOrderDetail(id);
        return Result.success(orderVO);
    }

    /**
     * 管理端-拒单
     * @param ordersRejectionDTO
     * @return
     */
    @ApiOperation("管理端-拒单")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("管理端-拒单：{}", ordersRejectionDTO);
        ordersService.rejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 管理端-接单
     * @param ordersConfirmDTO
     * @return
     */
    @ApiOperation("管理端-接单")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("管理端-接单:{}", ordersConfirmDTO);
        ordersService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 管理端-取消订单
     * @param ordersCancelDTO
     * @return
     */
    @ApiOperation("管理端-取消订单")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("管理端-取消订单:{}", ordersCancelDTO);
        ordersService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 管理端-派送订单
     * @param id
     * @return
     */
    @ApiOperation("管理端-派送订单")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Long id){
        log.info("管理端-派送订单：{}", id);
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 管理端-完成订单
     * @param id
     * @return
     */
    @ApiOperation("管理端-完成订单")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long id){
        log.info("管理端-完成订单:{}", id);
        ordersService.complete(id);
        return Result.success();
    }
}
